import json

import requests

headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36'
}
# url = 'https://httpbin.org/get?name=zdz'
#
# response = requests.get(url, headers=headers, params={'age': 10})
# print(response.status_code)
# if response.status_code == 200:
#     response_bytes = response.content
#     response_text = response_bytes.decode('utf-8')
#     response_json = json.loads(response_text)
#     print(response_json)
#
#     response_text = response.text
#     response_json = json.loads(response_text)
#     print(response_json)
#
#     response_json = response.json()
#     print(response_json)
#     print(response_json['headers']['User-Agent'])


# url = 'https://httpbin.org/post'
# response = requests.post(url, headers=headers, data={'name': 'zdz', 'age': 10})
# if response.status_code == 200:
#     # Content-Type : application/x-www-form-urlencoded
#     print(response.json()['headers']['Content-Type'])
#
# response = requests.post(url, headers=headers, json={'name': 'zdz', 'age': 10})
# if response.status_code == 200:
#     # Content-Type : application/json
#     print(response.json()['headers']['Content-Type'])

url = 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png'

response = requests.get(url, headers=headers)
if response.status_code == 200:
    with open('static/baidu.png', 'wb') as f:
        f.write(response.content)
